import 'css/common.css'
import './category.css'
import Foot from '@/components/Foot'
import Vue from 'vue'
import url from 'js/api.js'
import mixin from 'js/mixin.js'
import axios from 'axios'

let app = new Vue({
  el: '#app',
  data:{
    topList: null,
    topIndex: 0,
    rankList: null,
    subList: null
  },
  components: {
    Foot
  },
  created(){
    this.getTopList()
    this.getRank();
    if(this.topIndex !== 0){
      this.getSubList(0)
    }
  },
  methods:{
    getTopList(){
      axios.get(url.topList).then((res)=>{
        this.topList = res.data.lists
      })     
    },
    getRank(){
      axios.get(url.rank).then((res)=>{
        this.rankList = res.data.data
      })
    },
    getSubList(id){
      console.log('分类的id')
      console.log(id)
      axios.get(url.subList).then((res)=>{
        this.subList = res.data.data
      })
    },
    toSearch(list){
      location.href = `search.html?keyword=${list.name}&id=${list.id}`
    },
    /* 标签切换 */
    topListHandle(index, id){
      this.topIndex = index;
      if(index !== 0){
        this.getSubList(id)
      }else {
        // this.getRank()
      }
    },
    goSearch(){
      location.href = 'search.html'
    }
  },
  mixins: [mixin]
})
